package com.ssyc.student.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;

import com.ssyc.common.base.BaseActivity;
import com.ssyc.common.utils.GsonUtil;
import com.ssyc.student.R;
import com.ssyc.student.adapter.StGvAnswerAdapter;
import com.ssyc.student.bean.ChooseAnswerInfo;

import java.util.List;

/**
 * 学生端--语法检测--展示正确答案和错误答案的界面
 * Created by Kevin on 2018/6/4
 */

public class StudentShowGrammarAnswerActivity extends BaseActivity implements View.OnClickListener {

    //返回
    private ImageView ivBack;

    //展示正确或者错误答案的GridView
    private GridView gv;

    //重做
//    private Button btRetry;

    //查看答案
    private Button btLookAnswer;


    //学生作答题目正确或者错误的集合Json字符串
    private String answerJson;

    //用于展示答题选项的数据集合
    private List<ChooseAnswerInfo> datas;

    //展示答题选项的列表适配器
    private StGvAnswerAdapter adapter;

    @Override
    protected boolean isNeedShowTitle() {
        return false;
    }

    @Override
    protected String setTitleText() {
        return null;
    }

    @Override
    protected int getContentLayout() {
        return R.layout.student_activity_show_grammar_answer;
    }

    @Override
    protected void init() {
        initView();
        showContent();
        //获取页面数据
        initData();
        //设置列表
        initGv();
    }


    /**
     * 初始化View的操作
     */
    private void initView() {

        ivBack = findViewById(R.id.iv_back);
        ivBack.setOnClickListener(this);
        gv = findViewById(R.id.gv);
//        btRetry = findViewById(R.id.bt_retry);
        btLookAnswer = findViewById(R.id.bt_look_answer);
//        btRetry.setOnClickListener(this);
        btLookAnswer.setOnClickListener(this);

    }

    /**
     * 获取页面数据的方法
     */
    private void initData() {
        answerJson = getIntent().getStringExtra("data");
        if (!TextUtils.isEmpty(answerJson)) {
            datas = GsonUtil.jsonToList(answerJson, ChooseAnswerInfo[].class);
        }
    }

    /**
     * 设置展示正确或者错误答案的列表
     */
    private void initGv() {
        adapter = new StGvAnswerAdapter(this, datas, R.layout.student_rv_choose_answer);
        gv.setAdapter(adapter);
    }

    /**
     * 页面控件点击事件
     *
     * @param view
     */
    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.iv_back) {
            //返回
            finish();
        } else if (id == R.id.bt_retry) {
            //重试
        } else if (id == R.id.bt_look_answer) {
            //查看答案
            finish();
        }
    }
}
